package com.wu.prototype;

import java.io.*;

/**
 * @author wufei
 * @date 2018/1/16 15:13
 */
public class Room implements Cloneable , Serializable{

    private Table table;

    private String description;

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Table getTable() {
        return table;
    }

    public void setTable(Table table) {
        this.table = table;
    }

    @Override
    protected Room clone() throws CloneNotSupportedException {


        try {
            //序列化
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            ObjectOutputStream oos = new ObjectOutputStream(bos);
            oos.writeObject(this);

            //反序列化
            ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
            ObjectInputStream ois = new ObjectInputStream(bis);
            Object o = ois.readObject();

            //如果对象中有Date这类没序列化的对象需要单独处理

            //clone是字节码copy是不走构造方法的

            bos.close();
            oos.close();
            bis.close();
            ois.close();
            return (Room) o;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }


    }
}
